<?php
class Merchant_Service_Warehouse
{
	public static $type =array(
	    0 => '基本信息修改', 
	    1 => '库存变动'
	);
	
	public static function getShelfLogByProductId($productId,$page=null,$pageSize=null,$customerId=null){
		$results = array();
		$index=0;
		$total = 0;
		$startIndex = ($page-1)*$pageSize;
		$endIndex = $page*$pageSize;
		$wps = Merchant_Service_WarehouseProducts::getByProductId($productId,$customerId);
		if($wps){
			$logModel = new Merchant_Model_WarehouseShelfLog();
			foreach($wps as $key => $value){
				$total += $logModel->getByCondition(array("ws_code" => $value['ws_code']),"count(*)");
				$logs = $logModel->getByCondition(array("ws_code" => $value['ws_code']));
				foreach($logs as $log){
					if($index >= $startIndex && $index < $endIndex){
						$log['user'] = "System";
						if($log['user_id'] == -1){
							$log['user'] = "Yourself";
						}
						$log['type'] = self::$type[$log['wsl_type']];
						$results[$index]['log'] = $log;
						$results[$index]['wp'] = $value;
					}
					$index++;
				}
			}
		}
		$return["total"] = $total;
		$return["results"] = $results;
		return $return;
	}
	
	public static function getRowWarehouse($warehouseId){
		$whObj = new Merchant_Model_Warehouse();
		$warehouse = $whObj->getByValue($warehouseId,$field='warehouse_id');
		return $warehouse;
	}
	
	/*
	*获取仓库信息
	*/
	public static function getDetail($warehouseId){
		$whObj = new Merchant_Model_Warehouse();
		$warehouse = $whObj->getByValue($warehouseId,$field='warehouse_id');
		return $warehouse;
	}
	
	/**
	 * 获取所有仓储信息
	 */
	public static function getAll()
	{ 
		$obj=new Merchant_Model_Warehouse();
		return $obj->getAll();
	}
	
	/*
	获取可用的仓库信息
	*/
	public static function getByStatus(){
		$obj=new Merchant_Model_Warehouse();
		return $obj->getByStatus();
	}
}